<template>
  <div class="addNotice">
    <el-container>
      <el-header>Header</el-header>
      <el-main>
        <div style="width: 600px;">
          <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="标题" prop="noticetitle">
              <el-input v-model="ruleForm.noticetitle"></el-input>
            </el-form-item>
            <el-form-item label="通知简述" prop="showcontent" style="height: 50px;">
              <el-input type="textarea" v-model="ruleForm.showcontent"></el-input>
            </el-form-item>
            <el-form-item label="通知正文" prop="noticecontent">
              <el-input type="textarea" v-model="ruleForm.noticecontent" :rows="10"></el-input>
            </el-form-item>
             <el-form-item label="活动时间">
                <div class="block">
                    <el-date-picker
                      v-model="ruleForm.startdate"
                      type="datetime"
                      placeholder="开始日期">
                    </el-date-picker>
                     <el-date-picker
                        v-model="ruleForm.enddate"
                        type="datetime"
                        placeholder="截止日期">
                      </el-date-picker>
                  </div>

              </el-form-item>
            <el-form-item label="即时发布">
              <el-switch v-model="delivery"></el-switch>
            </el-form-item>


            <el-form-item>
              <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
              <el-button @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
          </el-form>
        </div>

      </el-main>
    </el-container>
  </div>
</template>

<script>
  export default {
    name:"addNotice",
    data() {
      return {
        ruleForm: {
          noticetitle: '',
          startdate:'',
          enddate:'',
          //简述
          showcontent: '',
          noticecontent: ''
        },
        delivery: false,
        rules: {
          noticetitle: [{
              required: true,
              message: '请输入活动名称',
              trigger: 'blur'
            },
            {
              min: 8,
              max: 15,
              message: '长度在 8 到 15 个字符',
              trigger: 'blur'
            }
          ],
          noticecontent: [{
            required: true,
            message: '请填写通知正文',
            trigger: 'blur'
          }],
          showcontent: [{
            required: true,
            message: '请填写通知简述',
            trigger: 'blur'
          }]
        }
      }
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$http.post("/repairNotice2/addNotice",this.ruleForm).then(resp=>{
              if(resp.data.code==200){
                alert("发布成功")
              }else{
                alert("出错了")
              }
              this.resetForm(formName)
            })
          } else {
            alert("请按照格式填写")
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        // this.ruleForm=null
        this.$refs[formName].resetFields();
      }
    },
    created() {

    }
  }
</script>

<style>
  .addNotice{
    background-repeat:repeat;
    background-image:url("") ;
  }
</style>
